﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraRichEdit.Commands;
using Marmat.Foundation;

namespace Marmat.Template.WinForm
{
    public partial class EditFormReportCollection : Marmat.Forms.Form
    {

        private Dictionary<IButtonItem, Rectangle> rectCollection = new Dictionary<IButtonItem, Rectangle>();
        private List<(IButtonItem, Func<IReportObject>)> reportCollection = new List<(IButtonItem, Func<IReportObject>)>();

        public EditFormReportCollection(List<(IButtonItem, Func<IReportObject>)> reportCollection)
        {
            InitializeComponent();
            this.reportCollection = reportCollection;
            this.comboBox1.Items.AddRange(reportCollection.Select(x => x.Item1).ToArray());
            if (this.comboBox1.Items.Count > 0)
                this.comboBox1.SelectedIndex = 0;
        }

        private void comboBox1_CustomDisplayText(object sender, Forms.CustomDisplayTextEventArgs e)
        {
            if (e.Value is IButtonItem item)
                e.DisplayText = item.Caption ?? item.Name;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (this.comboBox1.SelectedItem is IButtonItem item)
                this.reportCollection.FirstOrDefault(x => x.Item1 == item).Item2?.Invoke()?.Design();
        }
    }
}
